<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="../WEB-INF/template_admin.xhtml">
        <ui:define name="title">
            <h:outputText value="Administrar Pedidos"></h:outputText>
        </ui:define>
        <ui:define name="content">

            <br />
            <ul class="lista-mapa-sitio" style="margin-left: 200px">
                <li><a href="#{request.contextPath}/faces/administrador.xhtml">Administrar</a> / </li>
                <li>Pedidos</li>
            </ul>
            <p:fieldset legend="Pedidos" styleClass="panel-usuario" style="width: 900px">

                <p:growl id="growl" />
                <h:form styleClass="jsfcrud_list_form">
                    <h:panelGroup id="messagePanel" layout="block">
                        <p:messages autoUpdate="true"/>
                    </h:panelGroup>
                    <h:outputText escape="false" value="#{bundle.ListPedidoEmpty}" rendered="#{pedidoController.items.rowCount == 0}"/>
                    <h:panelGroup rendered="#{pedidoController.items.rowCount > 0}">
                        <h:outputText value="#{pedidoController.pagination.pageFirstItem + 1}..#{pedidoController.pagination.pageLastItem + 1}/#{pedidoController.pagination.itemsCount}"/>&nbsp;
                        <h:commandLink action="#{pedidoController.previous}" value="#{bundle.Previous} #{pedidoController.pagination.pageSize}" rendered="#{pedidoController.pagination.hasPreviousPage}"/>&nbsp;
                        <h:commandLink action="#{pedidoController.next}" value="#{bundle.Next} #{pedidoController.pagination.pageSize}" rendered="#{pedidoController.pagination.hasNextPage}"/>&nbsp;
                        <p:dataTable id="tbl" value="#{pedidoController.items}" var="item" emptyMessage="No se encontraron pedidos con ese criterio"
                                     widgetVar="userTable" paginator="true" rows="5" 
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                     rowsPerPageTemplate="5,10,20" editable="true">
                            <p:column>
                                <f:facet name="output">
                                    <h:outputText value="&nbsp;"/>
                                </f:facet>
                                <h:commandLink action="#{pedidoController.prepareEdit}" title="#{bundle.ListCategoriaEditLink}">
                                    <img src="../images/b_edit.png" width="16" height="16" alt="b_edit"/>
                                </h:commandLink>
                                <p:commandLink title="#{bundle.ListCategoriaDestroyLink}" update=":growl" onclick="cd.show()">
                                    <img src="../images/b_drop.png" width="16" height="16" alt="b_drop"/>
                                </p:commandLink>
                                <p:confirmDialog message="¿Está seguro de querer eliminar el registro?"
                                                 header="Iniciando proceso de eliminación" severity="alert"
                                                 widgetVar="cd">
                                    <p:commandButton value="Si" actionListener="#{pedidoController.destroy}"
                                                     update=":growl" oncomplete="cd.hide()"/>
                                    <p:commandButton value="No" onclick="cd.hide();" type="button" />
                                </p:confirmDialog>
                            </p:column>

                            <p:column headerText="Fecha y Hora" sortBy="#{item.pedFecha}" filterBy="#{item.pedFecha}">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value="#{item.pedFecha}">
                                            <f:convertDateTime pattern="dd/MM/yyy HH:mm:ss"/>
                                        </h:outputText>
                                    </f:facet>
                                    <f:facet name="input">  
                                        <h:form><p:calendar pattern="dd/MM/yyyy HH:mm:ss" value="#{item.pedFecha}"/></h:form>
                                    </f:facet> 
                                </p:cellEditor>
                            </p:column>
                            <p:column headerText="Estado" sortBy="#{item.pedEstadoId}" filterBy="#{item.pedEstadoId}">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:form><h:commandLink value="#{item.pedEstadoId}" disabled="true"/></h:form>
                                    </f:facet>
                                    <f:facet name="input">
                                        <h:form>
                                            <h:selectOneMenu value="#{pedidoController.selected.pedEstadoId}" style="width: 100%">
                                                <f:selectItems value="#{pedidoEstadoController.itemsAvailableSelectOne}"/>
                                            </h:selectOneMenu>
                                        </h:form>
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>
                            <p:column headerText="Medio de Pago" sortBy="#{item.pedMedPagoId}" filterBy="#{item.pedMedPagoId}">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:form><h:commandLink value="#{item.pedMedPagoId}" disabled="true"/></h:form>
                                    </f:facet>
                                    <f:facet name="input">
                                        <h:form>
                                            <h:selectOneMenu value="#{item.pedMedPagoId}" style="width: 100%">
                                                <f:selectItems value="#{medioPagoController.itemsAvailableSelectOne}"/>
                                            </h:selectOneMenu>
                                        </h:form>
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>
                            <p:column headerText="Atendido Por" sortBy="#{item.pedEmpId}" filterBy="#{item.pedEmpId}">
                                <f:facet name="output">
                                    <h:outputText value="#{bundle.ListPedidoTitle_pedEmpId}"/>
                                </f:facet>
                                <h:commandLink value="#{item.pedEmpId}" disabled="true"/>
                            </p:column>
                            <p:column headerText="Cliente" sortBy="#{item.pedUsuarioId}" filterBy="#{item.pedUsuarioId}">
                                <f:facet name="output">
                                    <h:outputText value="#{bundle.ListPedidoTitle_pedUsuarioId}"/>
                                </f:facet>
                                <h:commandLink value="#{item.pedUsuarioId}" disabled="true"/>
                            </p:column>
                            <p:column headerText="Opciones" style="width:50px">  
                                <p:rowEditor />  
                            </p:column> 
                        </p:dataTable>
                        <br />
                        <h:panelGrid columns="2">  
                            <p:panel header="Exportar Todo">  
                                <h:commandLink>  
                                    <p:graphicImage value="../images/excel.png" />  
                                    <p:dataExporter type="xls" target="tbl" fileName="pedidos" excludeColumns="0" postProcessor="#{exporterBean.postProcessXLS}"/>  
                                </h:commandLink>  
                                <h:commandLink>  
                                    <p:graphicImage value="../images/pdf.png" />  
                                    <p:dataExporter type="pdf" target="tbl" fileName="pedidos" excludeColumns="0" preProcessor="#{exporterBean.preProcessPDF}"/>  
                                </h:commandLink>  
                                <h:commandLink>  
                                    <p:graphicImage value="../images/csv.png" />  
                                    <p:dataExporter type="csv" target="tbl" fileName="pedidos" excludeColumns="0" />  
                                </h:commandLink>  
                            </p:panel>  

                            <p:panel header="Exportar Página">  
                                <h:commandLink>  
                                    <p:graphicImage value="../images/excel.png" />  
                                    <p:dataExporter type="xls" target="tbl" fileName="pedidos" pageOnly="true" excludeColumns="0" postProcessor="#{exporterBean.postProcessXLS}" />  
                                </h:commandLink>  
                                <h:commandLink>  
                                    <p:graphicImage value="../images/pdf.png" />  
                                    <p:dataExporter type="pdf" target="tbl" fileName="pedidos" pageOnly="true" excludeColumns="0" preProcessor="#{exporterBean.preProcessPDF}"/>  
                                </h:commandLink>  
                                <h:commandLink>  
                                    <p:graphicImage value="../images/csv.png" />  
                                    <p:dataExporter type="csv" target="tbl" fileName="pedidos" pageOnly="true" excludeColumns="0"/>  
                                </h:commandLink>  
                            </p:panel>  
                        </h:panelGrid> 
                    </h:panelGroup>
                    <br />
                    <br />
                </h:form>
            </p:fieldset>
        </ui:define>
    </ui:composition>

</html>
